import random
from Common.handle_db import HandleDB

prefix = [133, 149, 153, 173, 177, 180, 181, 189, 199,
          130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186, 166,
          134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 172, 178, 182, 183, 184, 187, 188, 198
          ]

def generator_new_phone():
    db=HandleDB()
    while True:
        phone_mem=generator_phone()
        count = db.select_count('select * from member where mobile_phone="{}"'.format(phone_mem))
        if count==0:
            db.close()
            return phone_mem


def generator_phone():
    index=random.randint(0,len(prefix)-1)
    phone=str(prefix[index])
    for i in range(8):
        phone+=str(random.randint(0,9))
    return phone

if __name__ == '__main__':
    phone=generator_new_phone()
    print(phone)

